﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Light.Framework.Model;
using System.Data;
using Light.Utility;

namespace Light.Framework.Contract
{

    /// <summary>
    /// 组件接口
    /// </summary>
    public interface IComponent
    {
        Dictionary<string, string> SearchFields { get; }
        ModelOrder ModelOrder { get; }

        OperateResult Delete(int id);
        OperateResult Delete(int[] ids);

        DataTable SearchTable(SearchArgs searchArgs, PageArgs pageArgs);

        int Count();
        int Count(SearchArgs args);

        /// <summary>
        /// 获取自定义收费项名称（导入导出时会使用）
        /// </summary>
        /// <returns></returns>
        Dictionary<string, string> GetCustomNames();

        /// <summary>
        /// 查询表或视图
        /// </summary>
        /// <param name="tableOrViewName"></param>
        /// <param name="searchArgs"></param>
        /// <param name="resultOrder"></param>
        /// <returns></returns>
        DataTable GetAll(string tableOrViewName, SearchArgs searchArgs, ResultOrder resultOrder);
        /// <summary>
        /// 分页查询表或视图
        /// </summary>
        /// <param name="tableOrViewName"></param>
        /// <param name="searchArgs"></param>
        /// <param name="pageArgs"></param>
        /// <param name="resultOrder"></param>
        /// <returns></returns>
        DataTable Search(string tableOrViewName, SearchArgs searchArgs, PageArgs pageArgs, ResultOrder resultOrder);
        /// <summary>
        /// 汇总
        /// </summary>
        /// <param name="tableOrViewName"></param>
        /// <param name="columnName"></param>
        /// <param name="searchArgs"></param>
        /// <returns></returns>
        decimal Sum(string tableOrViewName, string columnName, SearchArgs searchArgs);
    }

    /// <summary>
    /// 组件基接口(泛型)
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IComponent<T> : IComponent where T : class, IEntity, new()
    {

        OperateResult Create(T obj);

        OperateResult Delete(T model);
        OperateResult Delete(IList<T> models);

        OperateResult Update(T obj);
        OperateResult Save(T obj);
        OperateResult Import(List<T> models);

        /// <summary>
        /// 获取默认项，
        /// 若T实现了IDefaultable接口，则取IsDefault=true的对象
        /// 若未实现，则返回 new T();
        /// </summary>
        /// <returns></returns>
        T Get();
        T Get(int id);
        T Get(SearchArgs args);
        T Get(SearchArgs args, ModelOrder order);
        T Get(SearchArgs args, ModelOrder order, bool addOrgFilter);

        T Get(string propertyName, object value);
        T Get(string propertyName, object value, bool includeDelete);

        IList<T> GetAll();
        IList<T> GetAll(SearchArgs args);
        IList<T> Search(SearchArgs searchArgs, PageArgs pageArgs);
        IList<T> Search(SearchArgs args, int pageIndex, int pageSize, out int totalResult);
    }
}
